define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/index' + location.search,
                    add_url: 'user/add',
                   /* edit_url: 'user/edit',*/
                   /* del_url: 'user/del',*/
                    multi_url: 'user/multi',
                    import_url: 'user/import',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'parent_name', title: __('Parent_name'), operate: false},
                        {field: 'child_count', title: __('下级人数'), operate: false},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        /*{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},*/
                        /*{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
                            {
                                name: 'detail',
                                text: __('设置正常'),
                                icon: 'fa fa-check',
                                classname: 'btn btn-info btn-xs btn-detail btn-ajax',
//                                    extend:'data-area=\'["600px","400px"]\' data-shade=0.5',
                                url: 'user/status',
                                hidden:function(value,row){
                                    if(value.status == 0){
                                        return true; //或者return false
                                    }
                                },
                                success: function (data) {
                                    $(".btn-refresh").trigger("click");
                                }
                            },{
                                name: 'click',
                                text: __('设置禁用'),
                                icon: 'fa fa-close',
                                classname: 'btn btn-info btn-xs btn-detail btn-ajax',
                                extend: 'style="background-color:grey"',
                                url: 'user/no_status',
                                hidden:function(value,row){
                                    if(value.status == 1){
                                        return true; //或者return false
                                    }
                                },
                                success: function (data) {
                                    $(".btn-refresh").trigger("click");
                                }
                            }
                        ]}*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});